package com.welchapps.nporganizer;

import com.parse.ParseObject;
import com.welchapps.nporganizer.NotePad.DataCount;
import com.parse.ParseQueryAdapter;
import com.welchapps.nporganizer.NotePad.NoteColumns;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MyCursorAdapter extends ParseQueryAdapter<ParseObject> {
	
	public MyCursorAdapter(Context context, com.parse.ParseQueryAdapter.QueryFactory<ParseObject> queryFactory) {
		super(context, queryFactory);
	}
	
	@Override
	public View getItemView(ParseObject object, View view, ViewGroup parent) {
	  if (view == null) {
	    view = View.inflate(getContext(), R.layout.noteslist_item, null);
	  }
	  
	  // Take advantage of ParseQueryAdapter's getItemView logic for
	  // populating the main TextView/ImageView.
	  // The IDs in your custom layout must match what ParseQueryAdapter expects
	  // if it will be populating a TextView or ImageView for you.
	  super.getItemView(object, view, parent);
	 
	  // Do additional configuration before returning the View.
	  TextView name = (TextView)view.findViewById(android.R.id.text1);
	  TextView color = (TextView)view.findViewById(R.id.color);
	  TextView brand = (TextView)view.findViewById(R.id.text3);
	  
	  name.setText(object.getString("name"));
	  brand.setText(object.getString("brand"));
	  String s = object.getString("color").toLowerCase();
	  DataCount.addNew(object.getObjectId());
	  
	  if (s.contains("blue"))
	      color.setBackgroundColor(Color.parseColor("#0000FF"));
	  else if (s.contains("red"))
	      color.setBackgroundColor(Color.parseColor("#DC143C"));
	  else if (s.contains("pink"))
	      color.setBackgroundColor(Color.parseColor("#FF69B4"));
	  else if (s.contains("green"))
	      color.setBackgroundColor(Color.parseColor("#008000"));
	  else if (s.contains("white"))
	      color.setBackgroundColor(Color.parseColor("#FFFFFF"));   
	  else if (s.contains("gold"))
	      color.setBackgroundColor(Color.parseColor("#FFD700")); 
	  else if (s.contains("orange"))
	      color.setBackgroundColor(Color.parseColor("#FFA500")); 
	  else if (s.contains("purple"))
	      color.setBackgroundColor(Color.parseColor("#800080")); 
	  else if (s.contains("yellow"))
	      color.setBackgroundColor(Color.parseColor("#FFFF00")); 
	  else if (s.contains("silver"))
	      color.setBackgroundColor(Color.parseColor("#C0C0C0")); 
	  else 
		  color.setBackgroundColor(Color.parseColor("#000000"));
	  return view;
	}
 
	@Override
	public int getCount(){
		return super.getCount();
	}
//	public void bindView(View view, Context context, Cursor cursor) {
//			
//		TextView color = (TextView)view.findViewById(R.id.color);
//        String s = cursor.getString(
//				cursor.getColumnIndex(NoteColumns.COLOR)).toLowerCase();
//		TextView name = (TextView)view.findViewById(android.R.id.text1);
//
//		name.setText(cursor.getString(
//				cursor.getColumnIndex(NoteColumns.NAME)));
//		TextView brand = (TextView)view.findViewById(R.id.text3);
//		brand.setText(cursor.getString(
//				cursor.getColumnIndex(NoteColumns.BRAND)));
//			
//	    if (s.contains("blue"))
//	        color.setBackgroundColor(Color.parseColor("#0000FF"));
//	    else if (s.contains("red"))
//	        color.setBackgroundColor(Color.parseColor("#DC143C"));
//	    else if (s.contains("pink"))
//	        color.setBackgroundColor(Color.parseColor("#FF69B4"));
//	    else if (s.contains("green"))
//	        color.setBackgroundColor(Color.parseColor("#008000"));
//	    else if (s.contains("white"))
//	        color.setBackgroundColor(Color.parseColor("#FFFFFF"));   
//	    else if (s.contains("gold"))
//	        color.setBackgroundColor(Color.parseColor("#FFD700")); 
//	    else if (s.contains("orange"))
//	        color.setBackgroundColor(Color.parseColor("#FFA500")); 
//	    else if (s.contains("purple"))
//	        color.setBackgroundColor(Color.parseColor("#800080")); 
//	    else if (s.contains("yellow"))
//	        color.setBackgroundColor(Color.parseColor("#FFFF00")); 
//	    else if (s.contains("silver"))
//	        color.setBackgroundColor(Color.parseColor("#C0C0C0")); 
//	    else 
//	        color.setBackgroundColor(Color.parseColor("#000000"));
//
//
//	}
// 
//	@Override
//	public View newView(Context context, Cursor cursor, ViewGroup parent) {
//		LayoutInflater inflater = LayoutInflater.from(context);
//		View v = inflater.inflate(R.layout.noteslist_item, parent, false);
//		bindView(v, context, cursor);
//		return v;
//	}
}
